package cn.fl.flow.controller;

import cmm.flowweb.core.cmm.flow.utils.CmmFlowUtils;
import cmm.mid.core.framework.constant.DataResultConstant;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.bizflow.constant.SysBizFlowRlConstant;
import cn.fl.capital.constant.CapPayInfoConstant;
import cn.fl.capital.service.ICapPayInfoService;
import cn.fl.flow.service.IFlowService;
import cn.fl.flow.vo.FlowMyTaskVO;
import cn.fl.flow.vo.FlowTaskInfoVO;
import cn.fl.flow.vo.SysFlowAgentUsrVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.preloan.enums.LogBusinessTypeEnum;
import cn.fl.project.service.IPrjBscInfoService;
import cn.fl.system.constant.SysLogConstant;
import cn.fl.system.service.ISysUlFilesRecService;
import cn.fl.system.vo.SysFlowManageVVO;
import cn.fl.system.vo.SysFlowTaskHVO;
import cn.fl.system.vo.SysUlFilesRecVO;
import cn.fl.upload.constant.UploadConstant;
import cn.fl.warrant.service.IArcPostInfoService;
import cn.fl.warrant.vo.ArcPostInfoVO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lionbridge.activiti.constant.EnumInterface.TaskStatus;
import com.lionbridge.log.ext.ExtSlf4jLogger;
import com.lionbridge.log.ext.ExtSlf4jLoggerBuilder;
import com.lionbridge.log.ext.LogTypeEnum;
import fl.flow.facade.flow.api.IFlowQueryApiService;
import fl.flow.facade.flow.condition.FlowQueryCondition;
import fl.flow.facade.flow.condition.SysFlowManageVQueryCondition;
import fl.flow.facade.flow.condition.SysFlowSHQueryCondition;
import fl.flow.facade.flow.constant.FlowConstant;
import fl.flow.facade.flow.dto.FlowCompleteParamsDTO;
import fl.flow.facade.flow.dto.SysFlowSHDTO;
import fl.warrant.facade.archive.condition.ArcPostInfoQC;
import fl.warrant.facade.archive.constant.ArchiveConstants;
import flow.business.facade.flow.dto.FlowCompleteDTO;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.regex.Pattern;

/**
 * @Description: 流程任务控制器
 */
@Slf4j
@Controller
@RequestMapping("/flow/flow")
public class FlowController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(FlowController.class);

	private static ExtSlf4jLogger extSlf4jLogger = ExtSlf4jLoggerBuilder.create()
			.setBusinessType(LogBusinessTypeEnum.PRE_LOAN.getCode())
			.setSubBusinessType(LogBusinessTypeEnum.FLOW.getCode())
			.setLogType(LogTypeEnum.BUSINESS)
			.setLogger(log).build();

	/**
	 * 任务服务
	 */
	@Autowired
	private IFlowService flowService;

	/**
	 * 附件服务
	 */
	@Autowired
	private ISysUlFilesRecService sysUlFilesRecService;
	
	/**
	 * 流程查询API服务接口
	 */
	@Autowired
	private IFlowQueryApiService flowQueryApiService;

	/**
	 * 权证-邮寄信息 服务
	 */
	@Autowired
	private IArcPostInfoService arcPostInfoService;

	/**
	 * 付款信息 服务
	 */
	@Autowired
	private ICapPayInfoService capPayInfoService;


	/**
	 * 到我的任务列表页面
	 */
	@RequestMapping(value = "/toMyTaskDBPage.do", method = { RequestMethod.GET})
	public ModelAndView toMyTaskDBPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("flow/flow/myTaskDB");
		//任务源
		List<KeyValueVO> businessSourceList = this.flowService.searchBusinessSourceList();
		view.addObject("businessSourceList", businessSourceList);
		//业务类型
		List<KeyValueVO> businessTypeList = this.flowService.searchBusinessTypeList();
		view.addObject("businessTypeList", businessTypeList);

		//获取当前登录用户角色名称-判断是否为"权证人员"-REQ-4426
		Object object = CurrentThreadContext.getValue(CurrentThreadContext.CURRENT_ROLE_NM);
		if(null != object){
			String currentRoleNm = (String)object;
			if(StringUtils.isNotEmpty(currentRoleNm) && ("权证管理员".equals(currentRoleNm) || "权证组长".equals(currentRoleNm))){
				view.addObject("warrantFlag", "1");
			}else {
				view.addObject("warrantFlag", "0");
			}
			BaseLogUtils.info(logger, "toMyTaskDBPage", "[代办任务]-当前登录用户角色名称：" + currentRoleNm, CurrentThreadContext.getCurrentUserName());
		}

		return view;
	}

	/**
	 * 到我的任务挂起列表页面
	 */
	@RequestMapping(value = "/toMyTaskGQPage.do", method = { RequestMethod.GET})
	public ModelAndView toMyTaskGQPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("flow/flow/myTaskGQ");
		//任务源
		List<KeyValueVO> businessSourceList = this.flowService.searchBusinessSourceList();
		view.addObject("businessSourceList", businessSourceList);
		//业务类型
		List<KeyValueVO> businessTypeList = this.flowService.searchBusinessTypeList();
		view.addObject("businessTypeList", businessTypeList);
		return view;
	}
	
	/**
	 * 到我的任务完结列表页面
	 */
	@RequestMapping(value = "/toMyTaskWJPage.do", method = { RequestMethod.GET})
	public ModelAndView toMyTaskWJPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("flow/flow/myTaskWJ");
		//任务源
		List<KeyValueVO> businessSourceList = this.flowService.searchBusinessSourceList();
		view.addObject("businessSourceList", businessSourceList);
		//业务类型
		List<KeyValueVO> businessTypeList = this.flowService.searchBusinessTypeList();
		view.addObject("businessTypeList", businessTypeList);
		return view;
	}
	
	/**
	 * 到处理流程界面
	 * 进入当前节点处理界面,需要获取到当前流程一下参数进行查询相关节点信息
	 * 1、流程定义主键
	 * 2、流程实例主键
	 * 3、任务主键
	 */
	@RequestMapping(value = "/toExeFlowPage.do", method = { RequestMethod.GET})
	public ModelAndView toExeFlowPage(HttpServletRequest request, HttpServletResponse response) {
		String processDefinitionId = request.getParameter("processDefinitionId");
		String processInstanceId = request.getParameter("processInstanceId");
		String taskId = request.getParameter("taskId");
		String assignable = request.getParameter("assignable");//是否可分配(true-是,false-否)
		String formUrl = request.getParameter("formUrl");//task表单地址
		String flowList = request.getParameter("flowList");//task分出连线
		String processDefinitionKey = request.getParameter("processDefinitionKey");//流程定义标识(业务类型)
		String taskDefKey = request.getParameter("taskDefKey");//任务定义标识
		String businessKey = request.getParameter("businessKey");//业务数据ID
		String taskType = request.getParameter("taskType");//任务类型
		String status = request.getParameter("status");//任务状态
		String assignee = request.getParameter("assignee");//
		String originTaskId = request.getParameter("originTaskId");//原始任务ID
		String beanName = request.getParameter("beanName");//业务Bean名称
		String taskDefKeyNm = request.getParameter("taskDefKeyNm");//流程定义KEY名称
		String procNo = request.getParameter("procNo");
		String grpShr = request.getParameter("grpShr");//签收后组内是否可见
		String procNm = request.getParameter("procNm");
		String isSign = request.getParameter("isSign");
		String isFormAuth = request.getParameter("isFormAuth");//是否有节点表单权限
		String preTaskId = request.getParameter("preTaskId");//上一个节点任务ID,多个已逗号分割
		
		
		ModelAndView view = new ModelAndView("flow/flow/flowExe");
		view.addObject("processDefinitionId", processDefinitionId);
		view.addObject("processInstanceId", processInstanceId);
		view.addObject("taskId", taskId);
		view.addObject("assignable", assignable);
		view.addObject("flowList", flowList);
		view.addObject("processDefinitionKey", processDefinitionKey);
		view.addObject("taskDefKey", taskDefKey);
		view.addObject("businessKey", businessKey);
		view.addObject("taskType", taskType);
		view.addObject("taskStatus", status);
		view.addObject("assignee", assignee);
		view.addObject("originTaskId", originTaskId);
		view.addObject("taskDefKeyNm", taskDefKeyNm);
		view.addObject("procNo",procNo);
		view.addObject("grpShr",grpShr);
		view.addObject("procNm", procNm);
		view.addObject("isSign", isSign);
		view.addObject("isFormAuth", isFormAuth);
		view.addObject("preTaskId", preTaskId);
		Long usrId = CurrentThreadContext.getCurrentUserId();
		if(!assignee.equals(String.valueOf(usrId))){
			view.addObject("onlySave", true);
		}else{
			view.addObject("onlySave", false);
		}
		//判断当前的访问地址，如果是域名就映射域名，如果是IP就映射IP
		String _fromUrl = formUrl.replace("@", "&");
		view.addObject("formUrl", CmmFlowUtils.changeFlowShowUrlToTargetUrl(request, _fromUrl));
		String _flowPicUrl = PropertiesCacheUtils.getProperty(FlowConstant.FLOW_FLOW_PROPERTIES_TASK_PIC_URL)+processInstanceId;
		view.addObject("flowPicUrl", CmmFlowUtils.changeFlowShowUrlToTargetUrl(request, _flowPicUrl));//获取流程图地址及配置上参数
		view.addObject("beanName",beanName);
		return view;
	}
	
	/**
	 * 到处理流程界面-提供给任务管理列表使用
	 * 进入当前节点处理界面,需要获取到当前流程一下参数进行查询相关节点信息
	 * 1、流程定义主键
	 * 2、流程实例主键
	 * 3、任务主键
	 */
	@RequestMapping(value = "/toManageExeFlowPage.do", method = { RequestMethod.GET})
	public ModelAndView toManageExeFlowPage(HttpServletRequest request, HttpServletResponse response) {
		String processDefinitionId = request.getParameter("processDefinitionId");
		String processInstanceId = request.getParameter("processInstanceId");
		String taskId = request.getParameter("taskId");
		String assignable = request.getParameter("assignable");//是否可分配(true-是,false-否)
		String formUrl = request.getParameter("formUrl");//task表单地址
		String flowList = request.getParameter("flowList");//task分出连线
		String processDefinitionKey = request.getParameter("processDefinitionKey");//流程定义标识(业务类型)
		String taskDefKey = request.getParameter("taskDefKey");//任务定义标识
		String businessKey = request.getParameter("businessKey");//业务数据ID
		String taskType = request.getParameter("taskType");//任务类型
		String status = request.getParameter("status");//任务状态
		String assignee = request.getParameter("assignee");//
		String originTaskId = request.getParameter("originTaskId");//原始任务ID
		String beanName = request.getParameter("beanName");//业务Bean名称
		String taskDefKeyNm = request.getParameter("taskDefKeyNm");//流程定义KEY名称
		String procNo = request.getParameter("procNo");
		String grpShr = request.getParameter("grpShr");//签收后组内是否可见
		String procNm = request.getParameter("procNm");
		
		ModelAndView view = new ModelAndView("flow/sysflowmanage/flowExeManage");
		view.addObject("processDefinitionId", processDefinitionId);
		view.addObject("processInstanceId", processInstanceId);
		view.addObject("taskId", taskId);
		view.addObject("assignable", assignable);
		//view.addObject("formUrl", formUrl.replace("@", "&"));
		view.addObject("flowList", flowList);
		view.addObject("processDefinitionKey", processDefinitionKey);
		view.addObject("taskDefKey", taskDefKey);
		view.addObject("businessKey", businessKey);
		view.addObject("taskType", taskType);
		view.addObject("taskStatus", status);
		view.addObject("assignee", assignee);
		view.addObject("originTaskId", originTaskId);
		view.addObject("taskDefKeyNm", taskDefKeyNm);
		view.addObject("procNo",procNo);
		view.addObject("grpShr",grpShr);
		view.addObject("procNm", procNm);
		Long usrId = CurrentThreadContext.getCurrentUserId();
		if(!assignee.equals(String.valueOf(usrId))){
			view.addObject("onlySave", true);
		}else{
			view.addObject("onlySave", false);
		}

		String _fromUrl = formUrl.replace("@", "&");
		view.addObject("formUrl", CmmFlowUtils.changeFlowShowUrlToTargetUrl(request, _fromUrl));
		String _flowPicUrl = PropertiesCacheUtils.getProperty(FlowConstant.FLOW_FLOW_PROPERTIES_TASK_PIC_URL) + processInstanceId;
		view.addObject("flowPicUrl", CmmFlowUtils.changeFlowShowUrlToTargetUrl(request, _flowPicUrl));//获取流程图地址及配置上参数
		view.addObject("beanName",beanName);
		return view;
	}
	
	/**
	 * 流程查看页面
	 */
	@RequestMapping(value = "/toFlowShowPage.do", method = { RequestMethod.GET})
	public ModelAndView toFlowShowPage(HttpServletRequest request, HttpServletResponse response) {
		String processDefinitionId = request.getParameter("processDefinitionId");
		String processInstanceId = request.getParameter("processInstanceId");
		String taskId = request.getParameter("taskId");
		String assignable = request.getParameter("assignable");//是否可分配(true-是,false-否)
		String formUrl = request.getParameter("formUrl");//task表单地址
		String flowList = request.getParameter("flowList");//task分出连线
		String processDefinitionKey = request.getParameter("processDefinitionKey");//流程定义标识(业务类型)
		String taskDefKey = request.getParameter("taskDefKey");//任务定义标识
		String businessKey = request.getParameter("businessKey");//业务数据ID
		String taskType = request.getParameter("taskType");//任务类型
		String status = request.getParameter("status");//任务状态
		String assignee = request.getParameter("assignee");//受理人
		String businessType = request.getParameter("businessType");//业务类型
		String originTaskId = request.getParameter("originTaskId");//原始任务ID
		String beanName = request.getParameter("beanName");//业务Bean名称
		ModelAndView view = new ModelAndView("flow/flow/flowShow");
		view.addObject("processDefinitionId", processDefinitionId);
		view.addObject("processInstanceId", processInstanceId);
		view.addObject("taskId", taskId);
		view.addObject("assignable", assignable);
		//view.addObject("formUrl", formUrl);
		view.addObject("flowList", flowList);
		view.addObject("processDefinitionKey", processDefinitionKey);
		view.addObject("taskDefKey", taskDefKey);
		view.addObject("businessKey", businessKey);
		view.addObject("taskType", taskType);
		view.addObject("taskStatus", status);
		view.addObject("assignee", assignee);
		view.addObject("businessType", businessType);
		view.addObject("originTaskId", originTaskId);
		//view.addObject("flowPicUrl", PropertiesCacheUtils.getProperty(FlowConstant.FLOW_FLOW_PROPERTIES_FLOW_PIC_URL)+processInstanceId);//获取流程图地址及配置上参数
		view.addObject("beanName",beanName);
		String _fromUrl = formUrl;
		view.addObject("formUrl", CmmFlowUtils.changeFlowShowUrlToTargetUrl(request, _fromUrl));
		String _flowPicUrl = PropertiesCacheUtils.getProperty(FlowConstant.FLOW_FLOW_PROPERTIES_FLOW_PIC_URL) + processInstanceId;
		view.addObject("flowPicUrl", CmmFlowUtils.changeFlowShowUrlToTargetUrl(request, _flowPicUrl));//获取流程图地址及配置上参数

		return view;
	}
	
	/**
	 * 流程查看页面-各个业务模块数据点击流程编号调用
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/toFlowShowPageFowBus.do", method = { RequestMethod.GET})
	public ModelAndView toFlowShowPageFowBus(HttpServletRequest request, HttpServletResponse response) {
		String processDefinitionId = request.getParameter("pDefId");
		String processInstanceId = request.getParameter("pInsId");
		String taskId = request.getParameter("taskId");
		String status = request.getParameter("status");//任务状态
		String formUrl = request.getParameter("formUrl");//表单URL, 除了主键如果要带出其它参数必须把&写成@@, 后台我会把@@转换成&处理
		String businessKey = request.getParameter("businessKey");
		
		if(StringUtils.isEmpty(processDefinitionId)){
			processDefinitionId = "bus-0";
		}
		if(StringUtils.isEmpty(taskId)){
			try {
				String taskStatus = "suspended";
				FlowQueryCondition flowQueryCondition = new FlowQueryCondition();
				flowQueryCondition.setSysCd(CurrentThreadContext.getCurrentSysCd());
				flowQueryCondition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
				List<String> pInstIdList = new ArrayList<>();
				pInstIdList.add(processInstanceId);
				flowQueryCondition.setpInstIdList(pInstIdList);
				Pager page = new Pager();
				page.setCurrentPage(1);
				page.setEveryPage(10);//这里数据不会返回超过10条
				page.setCondition(flowQueryCondition);
				Pager pager = this.flowService.searchTaskRecordManagePage(page, CurrentThreadContext.getCurrentUserId(), taskStatus);
				List<FlowMyTaskVO> list = (List<FlowMyTaskVO>) pager.getResultList();
				if(CollectionUtils.isNotEmpty(list)){
					taskId = list.get(0).getTaskId();
					BaseLogUtils.info(logger, "toFlowShowPageFowBus", "查询历史流程操作-挂起任务ID:" + taskId, CurrentThreadContext.getCurrentUserName());
				}
			} catch (Exception e) {
				BaseLogUtils.info(logger, "toFlowShowPageFowBus", "获取历史流程操作-挂起任务ID失败,实例ID["+processInstanceId+"]:" + processInstanceId, CurrentThreadContext.getCurrentUserName());
			}
			if(StringUtils.isEmpty(taskId)){
				taskId = "bus-0";
			}
		}
		
		ModelAndView view = new ModelAndView("flow/flow/flowShow");
		//根据流程实例ID判断是否是老系统迁移数据,如果是迁移数据则跳转到提示页面
		if(StringUtils.isNotEmpty(processInstanceId)){
			String regex = "^a[\\d]*";    
	        boolean isOldPInst = Pattern.matches(regex, processInstanceId);
			if(isOldPInst){
				view.setViewName("flow/flow/flowTipToOldSys");
				return view;
			}
		}
		
		view.addObject("processDefinitionId", processDefinitionId);
		view.addObject("processInstanceId", processInstanceId);
		view.addObject("originTaskId", "bus-0");
		view.addObject("taskId", taskId);
		if(StringUtils.isEmpty(formUrl)){
			formUrl = "";
		}else{
			formUrl = formUrl.replace("@@", "&");//处理&符号
		}
		formUrl = CmmFlowUtils.changeFlowShowUrlToTargetUrl(request, formUrl);
		view.addObject("formUrl", formUrl);
		
		if(StringUtils.isEmpty(businessKey)){
			businessKey = "";
		}

		view.addObject("businessKey", businessKey);
		if(StringUtils.isNotEmpty(status) && status.equals(FlowConstant.FLOW_CHECK_STATE_PASS)){
			//view.addObject("flowPicUrl", PropertiesCacheUtils.getProperty(FlowConstant.FLOW_FLOW_PROPERTIES_FLOW_PIC_URL)+processInstanceId);//获取流程图地址及配置上参数
			String _flowPicUrl = PropertiesCacheUtils.getProperty(FlowConstant.FLOW_FLOW_PROPERTIES_FLOW_PIC_URL) + processInstanceId;
			view.addObject("flowPicUrl", CmmFlowUtils.changeFlowShowUrlToTargetUrl(request, _flowPicUrl));//获取流程图地址及配置上参数
		}else if(StringUtils.isNotEmpty(status) && (status.equals(FlowConstant.FLOW_CHECK_STATE_NO_PASS) || status.equals(FlowConstant.FLOW_CHECK_STATE_PRE_NO_PASS))){
			//view.addObject("flowPicUrl", PropertiesCacheUtils.getProperty(FlowConstant.FLOW_FLOW_PROPERTIES_FLOW_PIC_URL)+processInstanceId);//获取流程图地址及配置上参数
			String _flowPicUrl = PropertiesCacheUtils.getProperty(FlowConstant.FLOW_FLOW_PROPERTIES_FLOW_PIC_URL) + processInstanceId;
			view.addObject("flowPicUrl", CmmFlowUtils.changeFlowShowUrlToTargetUrl(request, _flowPicUrl));//获取流程图地址及配置上参数
		}else{
			//view.addObject("flowPicUrl", PropertiesCacheUtils.getProperty(FlowConstant.FLOW_FLOW_PROPERTIES_TASK_PIC_URL)+processInstanceId);//获取流程图地址及配置上参数
			String _flowPicUrl = PropertiesCacheUtils.getProperty(FlowConstant.FLOW_FLOW_PROPERTIES_TASK_PIC_URL) + processInstanceId;
			view.addObject("flowPicUrl", CmmFlowUtils.changeFlowShowUrlToTargetUrl(request, _flowPicUrl));//获取流程图地址及配置上参数
		}
		return view;
	}
	
	/**
	 * 选择组织中的人员WIN窗口内容
	 */
	@RequestMapping(value = "/toChooseUsrWinPage.do", method = { RequestMethod.GET})
	public ModelAndView toChooseUsrWinPage(HttpServletRequest request, HttpServletResponse response) {
		String isMore = request.getParameter("isMore");
		ModelAndView view = new ModelAndView("flow/flow/flowChooseUsr");
		view.addObject("isMore", isMore);
		return view;
	}


	/**
	 * 到我的任务列表页面
	 */
	@RequestMapping(value = "/toSetAgentUsrPage.do", method = { RequestMethod.GET})
	public ModelAndView toSetAgentUsrPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("flow/sysflowagentusr/flowAgentUsrList");
		return view;
	}
	
	/**
	 * 到代办人新增页面
	 */
	@RequestMapping(value = "/toAddFlowAgentUsrPage.do", method = { RequestMethod.GET})
	public ModelAndView toAddFlowAgentUsrPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("flow/sysflowagentusr/flowAgentUsrAdd");
		//加入流程定义
		List<KeyValueVO> searchSelectProcDefNameList = this.flowService.searchFlowAllowMe(CurrentThreadContext.getCurrentUserId(), 
				CurrentThreadContext.getCurrentOrgId(), CurrentThreadContext.getCurrentSysCd(), 1);//TODO 加入是否有权限查询
		view.addObject("searchSelectProcDefNameList", searchSelectProcDefNameList);
		return view;
	}


	/**
	 * 获取节点历史记录信息
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/initFlowTaskInfoList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initFlowTaskInfoList(HttpServletRequest request, HttpServletResponse response) {
		String  processDefinitionId = request.getParameter("processDefinitionId");
		String  processInstanceId = request.getParameter("processInstanceId");
		String  taskId = request.getParameter("taskId");
		String originTaskId = request.getParameter("originTaskId");
		
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		if(StringUtils.isEmpty(processDefinitionId) || StringUtils.isEmpty(processInstanceId) || StringUtils.isEmpty(taskId) || StringUtils.isEmpty(originTaskId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("流程参数不完整！"+ this.getRequestParameter(request));
			return result;
		}
		
		//通过这些数据调用服务获取节点信息返回
		List<FlowTaskInfoVO> flowTaskInfoVOList = this.flowService.searchFlowTaskVOInfoList(processDefinitionId, processInstanceId, taskId, originTaskId, false);
		//String xxx = JSON.toJSONString(flowTaskInfoVOList);
		if(CollectionUtils.isNotEmpty(flowTaskInfoVOList)){
			String servicePath = PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_SERVER_PATH);
			//设置前台显示的附件前缀
			for (FlowTaskInfoVO flowTaskInfoVO : flowTaskInfoVOList) {
				List<SysUlFilesRecVO> sysUlFilesRecVOList = flowTaskInfoVO.getAttchmntList();
				if(CollectionUtils.isNotEmpty(sysUlFilesRecVOList)){
					for (SysUlFilesRecVO sysUlFilesRecVO : sysUlFilesRecVOList) {
						sysUlFilesRecVO.setFilePath(servicePath+sysUlFilesRecVO.getFilePath());
					}
				}
			}
			result.setData(flowTaskInfoVOList);
		}else{
			result.setData(new ArrayList<FlowTaskInfoVO>());
		}
		return result;
	}
	
	/**
	 * 获取节点历史记录信息,带下一个节点提示
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/initFlowTaskInfoListWithNext.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initFlowTaskInfoListWithNext(HttpServletRequest request, HttpServletResponse response) {
		String  processDefinitionId = request.getParameter("processDefinitionId");
		String  processInstanceId = request.getParameter("processInstanceId");
		String  taskId = request.getParameter("taskId");
		String originTaskId = request.getParameter("originTaskId");
		
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		if(StringUtils.isEmpty(processDefinitionId) || StringUtils.isEmpty(processInstanceId) || StringUtils.isEmpty(taskId) || StringUtils.isEmpty(originTaskId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("流程参数不完整！"+ this.getRequestParameter(request));
			return result;
		}
		
		//通过这些数据调用服务获取节点信息返回
		List<FlowTaskInfoVO> flowTaskInfoVOList = this.flowService.searchFlowTaskVOInfoList(processDefinitionId, processInstanceId, taskId, originTaskId, true);
		//String xxx = JSON.toJSONString(flowTaskInfoVOList);
		if(CollectionUtils.isNotEmpty(flowTaskInfoVOList)){
			String servicePath = PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_SERVER_PATH);
			//设置前台显示的附件前缀
			for (FlowTaskInfoVO flowTaskInfoVO : flowTaskInfoVOList) {
				List<SysUlFilesRecVO> sysUlFilesRecVOList = flowTaskInfoVO.getAttchmntList();
				if(CollectionUtils.isNotEmpty(sysUlFilesRecVOList)){
					for (SysUlFilesRecVO sysUlFilesRecVO : sysUlFilesRecVOList) {
						sysUlFilesRecVO.setFilePath(servicePath+sysUlFilesRecVO.getFilePath());
					}
				}
			}
			result.setData(flowTaskInfoVOList);
		}else{
			result.setData(new ArrayList<FlowTaskInfoVO>());
		}
		return result;
	}
	
	/**
	 * 初始化待办列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initMyTaskDBList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initMyTaskDBList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		//flow.business.facade.flow.condition.FlowQueryCondition flowQueryCondition = new flow.business.facade.flow.condition.FlowQueryCondition();
        FlowQueryCondition flowQueryCondition = new FlowQueryCondition();
        flowQueryCondition.setSysCd(CurrentThreadContext.getCurrentSysCd());
		flowQueryCondition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		//获取查询条件
		this.getFlowQueryRequestParms(request, flowQueryCondition);
		//this.getFlowBusinessQueryRequestParms(request, flowQueryCondition);

		//获取是否为"权证人员"标识参数-REQ-4426
		String warrantFlag = request.getParameter("warrantFlag");
		if(StringUtils.isNotEmpty(warrantFlag) && "1".equals(warrantFlag)) {
			List<String> pInstIdList = new ArrayList<String>(); //流程实例ID集合
			Set<Long> dataIdList = new HashSet<Long>(); //业务主键集合
			List<Long> dataIdList2 = new ArrayList<Long>();
			String sendNum = request.getParameter("sendNum"); //快递单号
			if(StringUtils.isNotEmpty(sendNum)) {
				//1. 利用快递单号查询流程业务主键集合
				ArcPostInfoQC apiQC = new ArcPostInfoQC();
				apiQC.setSendNum(sendNum);
				//apiQC.setIsDel(BaseConstant.IS_YESNO_NO);
				List<ArcPostInfoVO> apiList = this.arcPostInfoService.searchList(apiQC);
				if(CollectionUtils.isNotEmpty(apiList) && apiList.size()>0) {
					for(ArcPostInfoVO apiVO : apiList) {
						//利用set不允许元素重复的性质去掉相同的元素
						dataIdList.add(apiVO.getArcAppId());
					}
				}
				//遍历set集合,转化成List集合
				for(Long set : dataIdList){
					dataIdList2.add(set);
				}
				//2. 根据流程业务主键集合获取权证相关流程实例ID集合
				SysFlowSHQueryCondition sfhQC = new SysFlowSHQueryCondition();
				sfhQC.setDataIdList(dataIdList2);
				sfhQC.setWordsInTheTable(ArchiveConstants.ARC_FLOW_S_H_ARC);
				sfhQC.setSysCd(CurrentThreadContext.getCurrentSysCd());
				List<SysFlowSHDTO> flowList = this.flowQueryApiService.searchFlowSHList(sfhQC);
				if(CollectionUtils.isNotEmpty(flowList) && flowList.size()>0) {
					for(SysFlowSHDTO sfhDTO : flowList) {
						pInstIdList.add(sfhDTO.getPInstId());
					}
				}
				//3. 设置代办任务列表页面查询条件：流程实例ID集合
				if(CollectionUtils.isNotEmpty(pInstIdList)) {
					flowQueryCondition.setpInstIdList(pInstIdList);
				}
				BaseLogUtils.info(logger, "initMyTaskDBList", "[代办任务]-快递单号：" + sendNum + "; 流程实例ID集合：" + JSONObject.toJSONString(pInstIdList), CurrentThreadContext.getCurrentUserName());
			}
		}
		page.setCondition(flowQueryCondition);
		Pager pager = this.flowService.searchMyTaskRecordPage(page, CurrentThreadContext.getCurrentUserId(), "");
		List<FlowMyTaskVO> list = (List<FlowMyTaskVO>) pager.getResultList();
		ListPageVO<FlowMyTaskVO> listPage = new ListPageVO<FlowMyTaskVO>(list, pager.getTotalCount());
		return listPage;
	}
	
	/**
	 * 初始化待办管理列表
	 * 本查询条件不加入当前人作为查询条件,就是说可以查询出来所有的任务,包括未设置处理人的任务
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initTaskDBManageList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initTaskDBManageList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		String taskStatus = "";
		String suspendedNm = request.getParameter("suspendedNm");//任务状态,如 suspended-挂起 processing/null/"" -正常
		if(StringUtils.isNotEmpty(suspendedNm) && suspendedNm.equals("true")){
			taskStatus = "suspended";
		}
		String taskTypeNm = request.getParameter("cancelNm");//任务状态,如 suspended-挂起 processing/null/"" -正常
		if(StringUtils.isNotEmpty(taskTypeNm) && taskTypeNm.equals("true")){
			taskStatus = "cancel";
		}
		
		FlowQueryCondition flowQueryCondition = new FlowQueryCondition();
		flowQueryCondition.setSysCd(CurrentThreadContext.getCurrentSysCd());
		flowQueryCondition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		//获取查询条件
		this.getFlowQueryRequestParms(request, flowQueryCondition);

		page.setCondition(flowQueryCondition);

		Pager pager = this.flowService.searchTaskRecordManagePage(page, CurrentThreadContext.getCurrentUserId(), taskStatus);
		List<FlowMyTaskVO> list = (List<FlowMyTaskVO>) pager.getResultList();
		ListPageVO<FlowMyTaskVO> listPage = new ListPageVO<FlowMyTaskVO>(list, pager.getTotalCount());
		return listPage;
	}

	/**
	 * 初始化挂起列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initMyTaskGQList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initMyTaskGQList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		FlowQueryCondition flowQueryCondition = new FlowQueryCondition();
		flowQueryCondition.setSysCd(CurrentThreadContext.getCurrentSysCd());
		flowQueryCondition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		//获取查询条件
		this.getFlowQueryRequestParms(request, flowQueryCondition);
		page.setCondition(flowQueryCondition);
		Pager pager = this.flowService.searchMyTaskRecordPage(page, CurrentThreadContext.getCurrentUserId(),TaskStatus.suspended.key());
		List<FlowMyTaskVO> list = (List<FlowMyTaskVO>) pager.getResultList();
		ListPageVO<FlowMyTaskVO> listPage = new ListPageVO<FlowMyTaskVO>(list, pager.getTotalCount());
		return listPage;
	}
	
	/**
	 * 初始化完结列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initMyTaskWJList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initMyTaskWJList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		FlowQueryCondition flowQueryCondition = new FlowQueryCondition();
		flowQueryCondition.setSysCd(CurrentThreadContext.getCurrentSysCd());
		flowQueryCondition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		//获取查询条件
		this.getFlowQueryRequestParms(request, flowQueryCondition);
		page.setCondition(flowQueryCondition);
		Pager pager = this.flowService.searchMyTaskWJPage(page, CurrentThreadContext.getCurrentUserId());
		List<FlowMyTaskVO> list = (List<FlowMyTaskVO>) pager.getResultList();
		ListPageVO<FlowMyTaskVO> listPage = new ListPageVO<FlowMyTaskVO>(list, pager.getTotalCount());
		return listPage;
	}
	
	/**
	 * 流程加签
	 */
	@RequestMapping(value = "/modifyFlowSign.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object modifyFlowSign(HttpServletRequest request, HttpServletResponse response) {
		String usrIds = request.getParameter("usrIds");
		String taskDefKey = request.getParameter("taskDefKey");
		String taskId = request.getParameter("taskId");
		String processDefinitionKey = request.getParameter("processDefinitionKey");
		String processDefinitionId = request.getParameter("processDefinitionId");
		//String attchmnt = request.getParameter("attchmnt");
		String taskOpinion = request.getParameter("taskOpinion");
		String businessKey = request.getParameter("businessKey");
		String processInstanceId = request.getParameter("processInstanceId");
		String businessType = request.getParameter("businessType");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		
		if(StringUtils.isEmpty(taskId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("任务ID不能为空！");
			return result;
		}
		
		if(StringUtils.isEmpty(usrIds)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("加签人员不能为空！");
			return result;
		}
		
		if(StringUtils.isEmpty(taskDefKey) 
				|| StringUtils.isEmpty(processDefinitionKey)
				|| StringUtils.isEmpty(processDefinitionId) 
				|| StringUtils.isEmpty(businessKey)
				|| !StringUtils.isNumeric(businessKey)//验证Long类型
				|| StringUtils.isEmpty(processInstanceId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("流程节点参数不完整！");
			return result;
		}
		
		try {
			SysFlowTaskHVO entity = new SysFlowTaskHVO();
			entity.setCrtTm(new Date());
			entity.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			entity.setBusinessKey(Long.valueOf(businessKey));
			entity.setIsDel(BaseConstant.IS_YESNO_NO);
			entity.setProcDefId(processDefinitionId);
			entity.setProcDefKey(processDefinitionKey);
			entity.setProcInstId(processInstanceId);
			entity.setSysCd(CurrentThreadContext.getCurrentSysCd());
			entity.setTaskDefKey(taskDefKey);
			entity.setTaskId(taskId);
			entity.setTaskOpinion(taskOpinion);
			entity.setBusinessType(businessType);
			
			List<String> toUsrIds = new ArrayList<>();
			JSONArray usrIdArray = JSONArray.fromObject(usrIds);
			for (Object object : usrIdArray) {
				toUsrIds.add(Long.valueOf(object.toString())+"");
			}
			
			entity.setToUsrIdList(toUsrIds);
			
			DataResultDTO dataResultDTO = this.flowService.modifyFlowSign(entity);
			if(null == dataResultDTO || !dataResultDTO.getCode().equals(BaseExceptionConstant.BASE_EXCEPTION_CODE_200)){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("操作失败！");
			}else{
				//加入附件,这里要容错,如果附件错误则忽略
				/*if(StringUtils.isNotEmpty(attchmnt)){
					Long hId = dataResultDTO.getId();
					if(StringUtils.isNotEmpty(hId)){
						FlowCompleteParamsDTO flowCompleteParamsDTO = new FlowCompleteParamsDTO();
						flowCompleteParamsDTO.setProcInstId(processInstanceId);
						flowCompleteParamsDTO.setTaskId(taskId);
						this.flowService.addFlowAttchmnt(hId, attchmnt, flowCompleteParamsDTO);
						uploadAttchment(request, result, hId, processInstanceId, taskId);
					}
				}*/
			}
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			logger.info(e.getMessage());
			BaseLogUtils.info(logger, "modifyFlowSign", "业务异常:" + e.getMessage());
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误！");
			BaseLogUtils.error(logger, "modifyFlowSign", "系统错误", e);
		}
		return result;
	}
	
	
	/**
	 * 流程签收-私有化
	 */
	@RequestMapping(value = "/modifyFlowPrivate.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object modifyFlowPrivate(HttpServletRequest request, HttpServletResponse response) {
		String taskDefKey = request.getParameter("taskDefKey");
		String taskId = request.getParameter("taskId");
		String processDefinitionKey = request.getParameter("processDefinitionKey");
		String processDefinitionId = request.getParameter("processDefinitionId");
		//String attchmnt = request.getParameter("attchmnt");
		//String taskOpinion = request.getParameter("taskOpinion");
		String businessKey = request.getParameter("businessKey");
		String processInstanceId = request.getParameter("processInstanceId");
		String businessType = request.getParameter("businessType");
		String businessBean=request.getParameter("businessBean");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		
		if(StringUtils.isEmpty(taskDefKey) 
				|| StringUtils.isEmpty(taskId) 
				|| StringUtils.isEmpty(processDefinitionKey)
				|| StringUtils.isEmpty(processDefinitionId) 
				|| StringUtils.isEmpty(businessKey)
				|| !StringUtils.isNumeric(businessKey)//验证Long类型
				|| StringUtils.isEmpty(processInstanceId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("流程节点参数不完整！");
			return result;
		}
		
		try {
			SysFlowTaskHVO entity = new SysFlowTaskHVO();
			entity.setCrtTm(new Date());
			entity.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			entity.setBusinessKey(Long.valueOf(businessKey));
			entity.setIsDel(BaseConstant.IS_YESNO_NO);
			entity.setProcDefId(processDefinitionId);
			entity.setProcDefKey(processDefinitionKey);
			entity.setProcInstId(processInstanceId);
			entity.setSysCd(CurrentThreadContext.getCurrentSysCd());
			entity.setTaskDefKey(taskDefKey);
			entity.setTaskId(taskId);
			//entity.setTaskOpinion(taskOpinion);
			entity.setBusinessType(businessType);
			entity.setBusinessBean(businessBean);
			
			result.setData(CurrentThreadContext.getCurrentUserId());
			Boolean pass = this.flowService.modifyFlowPrivate(entity);
			if(null == pass || pass == false){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("操作失败！");
			}else{
				//加入附件
			}
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			BaseLogUtils.info(logger, "modifyFlowPrivate", "业务异常:" + e.getMessage());
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误！");
			BaseLogUtils.error(logger, "modifyFlowPrivate", "系统错误", e);
		}
		return result;
	}
	
	/**
	 * 通过
	 */
	@RequestMapping(value = "/modifyFlowComplete.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object modifyFlowComplete(HttpServletRequest request, HttpServletResponse response) {
		String taskId = request.getParameter("taskId");
		String branchKey = request.getParameter("branchKey");
		String processDefinitionKey = request.getParameter("processDefinitionKey");//流程定义标识
		String taskDefKey = request.getParameter("taskDefKey");//任务定义标识

		String processDefinitionId = request.getParameter("processDefinitionId");
		//String attchmnt = request.getParameter("attchmnt");
		String taskOpinion = request.getParameter("taskOpinion");
		String businessKey = request.getParameter("businessKey");
		String processInstanceId = request.getParameter("processInstanceId");
		String businessType = request.getParameter("businessType");
		String businessBean = request.getParameter("businessBean");//获取任务节点配置的Bean
		String taskDefKeyNm = request.getParameter("taskDefKeyNm");
		String procNm = request.getParameter("procNm");//流程定义名称
		
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		if(StringUtils.isEmpty(taskId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("任务ID不能为空！");
			return result;
		}
		
		if(StringUtils.isEmpty(branchKey)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("流程branchKey不能为空！");
			return result;
		}
		
		if(StringUtils.isEmpty(processDefinitionKey)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("流程定义标识不能为空！");
			return result;
		}
		
		if(StringUtils.isEmpty(taskDefKey)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("任务定义标识不能为空！");
			return result;
		}
		
		if(StringUtils.isEmpty(processDefinitionId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("流程定义ID不能为空！");
			return result;
		}
		
		if(StringUtils.isEmpty(businessKey)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("流程业务主键不能为空！");
			return result;
		}
		
		if(StringUtils.isEmpty(processInstanceId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("流程实例ID不能为空！");
			return result;
		}
		
		try {

			FlowCompleteParamsDTO flowCompleteParamsDTO = new FlowCompleteParamsDTO();
			flowCompleteParamsDTO.setCrtTm(new Date());
			flowCompleteParamsDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			flowCompleteParamsDTO.setCrtUsrName(CurrentThreadContext.getCurrentUserName());
			flowCompleteParamsDTO.setBusinessKey(Long.valueOf(businessKey));
			flowCompleteParamsDTO.setIsDel(BaseConstant.IS_YESNO_NO);
			flowCompleteParamsDTO.setProcDefId(processDefinitionId);
			flowCompleteParamsDTO.setProcDefKey(processDefinitionKey);
			flowCompleteParamsDTO.setProcInstId(processInstanceId);
			flowCompleteParamsDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
			flowCompleteParamsDTO.setTaskDefKey(taskDefKey);
			flowCompleteParamsDTO.setTaskId(taskId);
			flowCompleteParamsDTO.setTaskOpinion(taskOpinion);
			flowCompleteParamsDTO.setBranchKey(branchKey);
			flowCompleteParamsDTO.setBusinessType(businessType);
			flowCompleteParamsDTO.setBusinessBean(businessBean);
			flowCompleteParamsDTO.setTaskDefNm(taskDefKeyNm);
			flowCompleteParamsDTO.setProcDefNm(procNm);
			flowCompleteParamsDTO.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
			BaseLogUtils.newLogger( "modifyFlowComplete.request:" + JSONObject.toJSONString(flowCompleteParamsDTO)).info();
			DataResultDTO dataResultDTO = this.flowService.modifyFlowComplete(flowCompleteParamsDTO);
			BaseLogUtils.newLogger( "modifyFlowComplete.response:" + JSONObject.toJSONString(dataResultDTO)).info();
			if(null == dataResultDTO || !dataResultDTO.getCode().equals(BaseExceptionConstant.BASE_EXCEPTION_CODE_200)){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("操作失败！");
			}else{
				Object resultObj=dataResultDTO.getData();
				//判断返回结果
				if(null != dataResultDTO.getData()) {
					//返回结果为String 直接返回下一节点操作人
					if (resultObj instanceof String) {
						BaseLogUtils.info(logger, "modifyFlowComplete", "返回人员" + dataResultDTO.getData().toString());
						result.setInfo(DataResultConstant.IS_YESNO_NO);
						result.setData(dataResultDTO.getData());
					} else if (resultObj instanceof FlowCompleteDTO) {
						//返回mqkey
						FlowCompleteDTO dto = (FlowCompleteDTO) dataResultDTO.getData();
						BaseLogUtils.info(logger, "modifyFlowComplete", "返回mqKey" + dto.getMqKey());
						result.setInfo(DataResultConstant.IS_YESNO_YES);
						result.setData(dto.getMqKey());
					}
				}
			}
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			BaseLogUtils.info(logger, "modifyFlowComplete", "业务异常:" + e.getMessage());
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误！");
			BaseLogUtils.error(logger, "modifyFlowComplete", "系统错误", e);
		}
		return result;
	}
	
	/**
	 * 节点上传保存记录
	 */
	@RequestMapping(value = "/uploadFlowOperator.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object uploadFlowOperator(HttpServletRequest request, HttpServletResponse response) {
		String taskId = request.getParameter("taskId");
		String attchmnt = request.getParameter("attchmnt");
		String processInstanceId = request.getParameter("processInstanceId");
		String businessKey = request.getParameter("businessKey");
		
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		if(StringUtils.isEmpty(taskId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("任务ID不能为空！");
			return result;
		}
		
		if(StringUtils.isEmpty(processInstanceId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("流程实例ID不能为空！");
			return result;
		}
		
		if(StringUtils.isEmpty(businessKey)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("流程业务主键不能为空！");
			return result;
		}
		
		if(StringUtils.isEmpty(attchmnt)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("附件不存在！");
			return result;
		}
		
		try {
			//加入附件,这里要容错,如果附件错误则忽略
			uploadAttchment(request, result, taskId, processInstanceId, taskId);
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			BaseLogUtils.info(logger, "uploadFlowOperator", "业务异常:" + e.getMessage());
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误！");
			BaseLogUtils.error(logger, "uploadFlowOperator", "系统错误", e);
		}
		return result;
	}
	
	private void uploadAttchment(HttpServletRequest request, DataResultVO result, String id, String procInstId, String taskId ) {
		String attchmnt = request.getParameter("attchmnt");
		if(StringUtils.isNotEmpty(attchmnt)){
			//上传解析
			try{
				String cfgCd = PropertiesCacheUtils.getProperty(FlowConstant.COMM_FILE_REC_CFG_CD);
				String cfgDtlCd = PropertiesCacheUtils.getProperty(FlowConstant.COMM_FILE_REC_CFG_DTL_CD);
				String tabNm = PropertiesCacheUtils.getProperty(FlowConstant.COMM_FILE_REC_TABNM);
				String cfgOrgCd = PropertiesCacheUtils.getProperty(FlowConstant.COMM_FILE_REC_CFG_ORG_CD);
				Boolean attchmntPass = this.sysUlFilesRecService.addAttchmnt(id, attchmnt, cfgCd, cfgDtlCd, tabNm, "流程处理中上传附件!", procInstId, taskId, false, cfgOrgCd);
				if(null == attchmntPass || attchmntPass == false){
					result.setInfo("附件上传失败!");
				}
			}catch(Exception e){
				result.setInfo("附件上传失败!");
			}
		}
	}
	
	/**
	 * 流程分配
	 */
	@RequestMapping(value = "/modifyFlowDistribute.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object modifyFlowDistribute(HttpServletRequest request, HttpServletResponse response) {
		String usrIds = request.getParameter("usrIds");
		String taskDefKey = request.getParameter("taskDefKey");
		String taskId = request.getParameter("taskId");
		String processDefinitionKey = request.getParameter("processDefinitionKey");
		String processDefinitionId = request.getParameter("processDefinitionId");
		//String attchmnt = request.getParameter("attchmnt");
		String taskOpinion = request.getParameter("taskOpinion");
		String businessKey = request.getParameter("businessKey");
		String processInstanceId = request.getParameter("processInstanceId");
		String businessType = request.getParameter("businessType");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		if(StringUtils.isEmpty(taskId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("任务ID不能为空！");
			return result;
		}
		
		if(StringUtils.isEmpty(usrIds)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("分配人员不能为空！");
			return result;
		}
		
		if(StringUtils.isEmpty(taskDefKey) 
				|| StringUtils.isEmpty(processDefinitionKey)
				|| StringUtils.isEmpty(processDefinitionId) 
				|| StringUtils.isEmpty(businessKey)
				|| !StringUtils.isNumeric(businessKey)//验证Long类型
				|| StringUtils.isEmpty(processInstanceId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("流程节点参数不完整！");
			return result;
		}
		
		try {
			SysFlowTaskHVO sysFlowTaskHVO = new SysFlowTaskHVO();
			sysFlowTaskHVO.setCrtTm(new Date());
			sysFlowTaskHVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			sysFlowTaskHVO.setBusinessKey(Long.valueOf(businessKey));
			sysFlowTaskHVO.setIsDel(BaseConstant.IS_YESNO_NO);
			sysFlowTaskHVO.setProcDefId(processDefinitionId);
			sysFlowTaskHVO.setProcDefKey(processDefinitionKey);
			sysFlowTaskHVO.setProcInstId(processInstanceId);
			sysFlowTaskHVO.setSysCd(CurrentThreadContext.getCurrentSysCd());
			sysFlowTaskHVO.setTaskDefKey(taskDefKey);
			sysFlowTaskHVO.setTaskId(taskId);
			sysFlowTaskHVO.setTaskOpinion(taskOpinion);
			sysFlowTaskHVO.setBusinessType(businessType);
			
			List<String> toUsrIds = new ArrayList<>();
			JSONArray usrIdArray = JSONArray.fromObject(usrIds);
			for (Object object : usrIdArray) {
				toUsrIds.add(Long.valueOf(object.toString())+"");
			}
			
			sysFlowTaskHVO.setToUsrIdList(toUsrIds);
			
			DataResultDTO dataResultDTO = this.flowService.modifyFlowDistribute(sysFlowTaskHVO);
			if(null == dataResultDTO || !dataResultDTO.getCode().equals(BaseExceptionConstant.BASE_EXCEPTION_CODE_200)){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("操作失败！");
			}else{
				//加入附件,这里要容错,如果附件错误则忽略
				/*if(StringUtils.isNotEmpty(attchmnt)){
					Long hId = dataResultDTO.getId();
					if(StringUtils.isNotEmpty(hId)){
						FlowCompleteParamsDTO flowCompleteParamsDTO = new FlowCompleteParamsDTO();
						flowCompleteParamsDTO.setProcInstId(processInstanceId);
						flowCompleteParamsDTO.setTaskId(taskId);
						this.flowService.addFlowAttchmnt(hId, attchmnt, flowCompleteParamsDTO);
						uploadAttchment(request, result, hId, processInstanceId, taskId);
					}
				}*/
			}
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			BaseLogUtils.info(logger, "modifyFlowDistribute", "业务异常:" + e.getMessage());
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误！");
			BaseLogUtils.error(logger, "modifyFlowDistribute", "系统错误", e);
		}
		return result;
	}
	
	
	/**
	 * 暂不处理
	 */
	@RequestMapping(value = "/modifyFlowHold.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object modifyFlowHold(HttpServletRequest request, HttpServletResponse response) {

		String taskDefKey = request.getParameter("taskDefKey");
		String taskId = request.getParameter("taskId");
		String processDefinitionKey = request.getParameter("processDefinitionKey");
		String processDefinitionId = request.getParameter("processDefinitionId");
		String attchmnt = request.getParameter("attchmnt");
		String taskOpinion = request.getParameter("taskOpinion");
		String businessKey = request.getParameter("businessKey");
		String processInstanceId = request.getParameter("processInstanceId");
		String businessType = request.getParameter("businessType");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");

		if(StringUtils.isEmpty(taskId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("任务ID不能为空！");
			return result;
		}
		if(StringUtils.isEmpty(processInstanceId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("流程实例ID不能为空！");
			return result;
		}
		
		if(StringUtils.isEmpty(taskDefKey) 
				|| StringUtils.isEmpty(processDefinitionKey)
				|| StringUtils.isEmpty(processDefinitionId) 
				|| StringUtils.isEmpty(businessKey)
				|| !StringUtils.isNumeric(businessKey)//验证Long类型
				|| StringUtils.isEmpty(processInstanceId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("流程节点参数不完整！");
			return result;
		}

		try {
			SysFlowTaskHVO sysFlowTaskHVO = new SysFlowTaskHVO();
			sysFlowTaskHVO.setCrtTm(new Date());
			sysFlowTaskHVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			sysFlowTaskHVO.setBusinessKey(Long.valueOf(businessKey));
			sysFlowTaskHVO.setIsDel(BaseConstant.IS_YESNO_NO);
			sysFlowTaskHVO.setProcDefId(processDefinitionId);
			sysFlowTaskHVO.setProcDefKey(processDefinitionKey);
			sysFlowTaskHVO.setProcInstId(processInstanceId);
			sysFlowTaskHVO.setSysCd(CurrentThreadContext.getCurrentSysCd());
			sysFlowTaskHVO.setTaskDefKey(taskDefKey);
			sysFlowTaskHVO.setTaskId(taskId);
			if(StringUtils.isEmpty(taskOpinion)){
				taskOpinion = "挂起任务！";
			}
			sysFlowTaskHVO.setTaskOpinion(taskOpinion);
			sysFlowTaskHVO.setBusinessType(businessType);
			if(StringUtils.isNotEmpty(attchmnt)){
				attchmnt = attchmnt.replace("[", "").replace("]", "");
				sysFlowTaskHVO.setAttchmntList(Arrays.asList(attchmnt));
			}

			DataResultDTO dataResultDTO = this.flowService.modifyFlowHold(sysFlowTaskHVO);
			if(null == dataResultDTO || !dataResultDTO.getCode().equals(BaseExceptionConstant.BASE_EXCEPTION_CODE_200)){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("操作失败！");
			}else{
				//加入附件,这里要容错,如果附件错误则忽略
				/*if(StringUtils.isNotEmpty(attchmnt)){
					Long hId = dataResultDTO.getId();
					if(StringUtils.isNotEmpty(hId)){
						FlowCompleteParamsDTO flowCompleteParamsDTO = new FlowCompleteParamsDTO();
						flowCompleteParamsDTO.setProcInstId(processInstanceId);
						flowCompleteParamsDTO.setTaskId(taskId);
						this.flowService.addFlowAttchmnt(hId, attchmnt, flowCompleteParamsDTO);
						uploadAttchment(request, result, hId, processInstanceId, taskId);
					}
				}*/
			}
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			BaseLogUtils.info(logger, "modifyFlowHold", "业务异常:" + e.getMessage());
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误！");
			BaseLogUtils.error(logger, "modifyFlowHold", "系统错误", e);
		}
		return result;
	}
	
	/**
	 * 恢复挂起流程
	 */
	@RequestMapping(value = "/modifyFlowRecover.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object modifyFlowRecover(HttpServletRequest request, HttpServletResponse response) {
		String taskId = request.getParameter("taskId");
		String processInstanceId = request.getParameter("processInstanceId");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		if(StringUtils.isEmpty(taskId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("任务ID不能为空！");
			return result;
		}
		if(StringUtils.isEmpty(processInstanceId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("流程实例ID不能为空！");
			return result;
		}
		try {
			Boolean pass = this.flowService.modifyFlowRecover(CurrentThreadContext.getCurrentUserId(), taskId, processInstanceId);
			if(null == pass || pass == false){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("操作失败！");
			}
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			BaseLogUtils.info(logger, "modifyFlowRecover", "业务异常:" + e.getMessage());
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误！");
			BaseLogUtils.error(logger, "modifyFlowRecover", "系统错误", e);
		}
		return result;
	}

	/**
	 * 驳回
	 */
	@RequestMapping(value = "/modifyFlowRefused.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object modifyFlowRefused(HttpServletRequest request, HttpServletResponse response) {
		String taskId = request.getParameter("taskId");
		//String processDefinitionKey = request.getParameter("processDefinitionKey");
		//String taskDefKey = request.getParameter("taskDefKey");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		if(StringUtils.isEmpty(taskId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("任务ID不能为空！");
			return result;
		}
		try {
			Boolean pass = this.flowService.modifyFlowRefused(CurrentThreadContext.getCurrentUserId(), taskId);
			if(null == pass || pass == false){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("操作失败！");
			}
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			BaseLogUtils.info(logger, "modifyFlowRefused", "业务异常:" + e.getMessage());
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误！");
			BaseLogUtils.error(logger, "modifyFlowRefused", "系统错误", e);
		}
		return result;
	}
	
	
	/**
	 * 初始化流程管理列表
	 */
	/*@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initFlowManagePageList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initFlowManagePageList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		
		FlowQueryCondition flowQueryCondition = new FlowQueryCondition();
		flowQueryCondition.setSysCd(CurrentThreadContext.getCurrentSysCd());
		flowQueryCondition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());

		Pager pager = this.flowService.searchMyTaskRecordPage(page, CurrentThreadContext.getCurrentUserId());
		List<FlowMyTaskVO> list = (List<FlowMyTaskVO>) pager.getResultList();
		ListPageVO<FlowMyTaskVO> listPage = new ListPageVO<FlowMyTaskVO>(list, pager.getTotalCount());
		return listPage;
	}*/

	/**
	 * 初始化流程设置代办人列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initFlowAgentUsrList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initFlowAgentUsrList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		
		FlowQueryCondition flowQueryConditon = new FlowQueryCondition();
		flowQueryConditon.setSysCd(CurrentThreadContext.getCurrentSysCd());
		page.setCondition(flowQueryConditon);
		Pager pager = this.flowService.searchFlowAgentUsrListPage(CurrentThreadContext.getCurrentUserId(), page);
		List<SysFlowAgentUsrVO> list = (List<SysFlowAgentUsrVO>) pager.getResultList();
		ListPageVO<SysFlowAgentUsrVO> listPage = new ListPageVO<SysFlowAgentUsrVO>(list, pager.getTotalCount());
		return listPage;
	}
	
	/**
	 * 新增代办人
	 */
	@RequestMapping(value = "/addFlowAgentUsr.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object addFlowAgentUsr(HttpServletRequest request, HttpServletResponse response) {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		String procDefKey = request.getParameter("procDefKey");
		String agentUsrId = request.getParameter("agentUsrId");
		String startTm = request.getParameter("startTm");
		String endTm = request.getParameter("endTm");
		
		if(StringUtils.isEmpty(procDefKey)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("请选择流程定义！");
			return result;
		}
		
		if(StringUtils.isEmpty(agentUsrId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("请选择代办人！");
			return result;		
		}
		
		if(StringUtils.isEmpty(startTm)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("请选择开始时间！");
			return result;	
		}
		
		if(StringUtils.isEmpty(endTm)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("请选择结束时间！");
			return result;	
		}
		
		try {
			SysFlowAgentUsrVO sysFlowAgentUsrVO = new SysFlowAgentUsrVO();
			sysFlowAgentUsrVO.setProcessDefKey(procDefKey);
			sysFlowAgentUsrVO.setEntrustUsrId(Long.valueOf(agentUsrId));
			sysFlowAgentUsrVO.setStartTm(DateUtils.formatStringToDate(startTm, DateUtils.YYYY_MM_DDHHMMSS));
			sysFlowAgentUsrVO.setEndTm(DateUtils.formatStringToDate(endTm, DateUtils.YYYY_MM_DDHHMMSS));
			sysFlowAgentUsrVO.setUsrId(CurrentThreadContext.getCurrentUserId());
			sysFlowAgentUsrVO.setSysCd(CurrentThreadContext.getCurrentSysCd());
			
			if(null == sysFlowAgentUsrVO.getStartTm() || sysFlowAgentUsrVO.getStartTm().before(DateUtils.getDateAddDate(new Date(), 12, -1))){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("开始时间不能小于当前时间！");
				return result;
			}
			
			if(null == sysFlowAgentUsrVO.getEndTm() || sysFlowAgentUsrVO.getEndTm().before(sysFlowAgentUsrVO.getStartTm())){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("结束时间不能小于开始时间！");
				return result;
			}
			
			
			Boolean pass = this.flowService.addFlowAgentUsr(sysFlowAgentUsrVO);
			if(null == pass || pass == false){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("操作失败！");
			}
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			BaseLogUtils.info(logger, "addFlowAgentUsr", "业务异常:" + e.getMessage());
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误！");
			BaseLogUtils.error(logger, "addFlowAgentUsr", "系统错误", e);
		}
		return result;
	}
	
	@RequestMapping(value = "/removeFlowAgentUsr.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object removeFlowAgentUsr(HttpServletRequest request, HttpServletResponse response) {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		String dataId = request.getParameter("id");
		if(StringUtils.isEmpty(dataId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("数据主键不存在！");
			return result;
		}
		
		try {
			Boolean pass = this.flowService.removeFlowAgentUsr(dataId);
			if(null == pass || pass == false){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("操作失败！");
			}
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			BaseLogUtils.info(logger, "removeFlowAgentUsr", "业务异常:" + e.getMessage());
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误！");
			BaseLogUtils.error(logger, "removeFlowAgentUsr", "系统错误", e);
		}
		return result;
	}


	private void getFlowBusinessQueryRequestParms(HttpServletRequest request, flow.business.facade.flow.condition.FlowQueryCondition flowQueryCondition) {
		String flowDefNm = request.getParameter("flowDefNm");
		String taskNm = request.getParameter("taskNm");
		String cstNm = request.getParameter("cstNm");//大字段值
		String prjNm = request.getParameter("prjNm");//大字段值
		String orgDispNm = request.getParameter("orgDispNm");//大字段值
		String businessType = request.getParameter("businessType");
		String bizResCd = request.getParameter("bizResCd");//任务源
		String initiator = request.getParameter("initiator");
		String viKey = request.getParameter("viKey");//大字段值(主要关键字)
		String startTmStart = request.getParameter("startTmStart");
		String startTmEnd = request.getParameter("startTmEnd");
		String endTmStart = request.getParameter("endTmStart");
		String endTmEnd = request.getParameter("endTmEnd");
		String procNo = request.getParameter("procNo");//流程编号
		String searchOrgCd = request.getParameter("searchOrgCd");//组织机构代码-查询使用-和正常使用的当前组织机构代码区分
		String assigneeNm = request.getParameter("assigneeNm");//新处理人
		String ownerNm = request.getParameter("ownerNm");//原处理人
		String key1 = request.getParameter("viKey1");// 关键字key1


		if(StringUtils.isNotEmpty(key1)){
			flowQueryCondition.setKey1(key1);
		}

		if(StringUtils.isNotEmpty(procNo)){
			flowQueryCondition.setProcNo(procNo);
		}

		if(StringUtils.isNotEmpty(flowDefNm)){
			flowQueryCondition.setFlowDefNm(flowDefNm);
		}

		if(StringUtils.isNotEmpty(taskNm)){
			flowQueryCondition.setTaskNm(taskNm);
		}

		if(StringUtils.isNotEmpty(orgDispNm)){
			flowQueryCondition.setOrgDispNm(orgDispNm);
		}

		if(StringUtils.isNotEmpty(searchOrgCd)){
			flowQueryCondition.setSearchOrgCd(searchOrgCd);
		}
		/*if(StringUtils.isNotEmpty(businessType)){
			flowQueryCondition.setBusinessType(businessType);
		}*/
		if(StringUtils.isNotEmpty(bizResCd)){
			flowQueryCondition.setBizResCd(bizResCd);
		}
		if(StringUtils.isNotEmpty(initiator)){
			flowQueryCondition.setInitiatorNm(initiator);
		}

		if(StringUtils.isNotEmpty(assigneeNm)){
			flowQueryCondition.setAssigneeNm(assigneeNm);
		}

		if(StringUtils.isNotEmpty(ownerNm)){
			flowQueryCondition.setOwnerNm(ownerNm);
		}

		StringBuffer key = new StringBuffer();//大字段查询

		if(StringUtils.isNotEmpty(viKey)){
			key.append(FlowConstant.FLOW_QUERY_CONDITION_SEPERATOR);
			key.append(viKey);
		}

		if(StringUtils.isNotEmpty(businessType)){
			key.append(FlowConstant.FLOW_QUERY_CONDITION_SEPERATOR);
			key.append(businessType);
		}

		if(StringUtils.isNotEmpty(cstNm)){
			flowQueryCondition.setCstNm(cstNm);
		}

		if(StringUtils.isNotEmpty(prjNm)){
			key.append(FlowConstant.FLOW_QUERY_CONDITION_SEPERATOR);
			key.append(prjNm);
		}

		if(StringUtils.isNotEmpty(orgDispNm)){
			key.append(FlowConstant.FLOW_QUERY_CONDITION_SEPERATOR);
			key.append(orgDispNm);
		}

		if(StringUtils.isNotEmpty(key.toString())){
			flowQueryCondition.setViKey(key.toString());
		}

		if(StringUtils.isNotEmpty(startTmStart)){
			flowQueryCondition.setStartTmStart(DateUtils.formatStringToDate(startTmStart + " 00:00:00", DateUtils.YYYY_MM_DDHHMMSS));
		}
		if(StringUtils.isNotEmpty(startTmEnd)){
			flowQueryCondition.setStartTmEnd(DateUtils.formatStringToDate(startTmEnd + " 23:59:59", DateUtils.YYYY_MM_DDHHMMSS));
		}
		if(StringUtils.isNotEmpty(endTmStart)){
			flowQueryCondition.setEndTmStart(DateUtils.formatStringToDate(endTmStart + " 00:00:00", DateUtils.YYYY_MM_DDHHMMSS));
		}
		if(StringUtils.isNotEmpty(endTmEnd)){
			flowQueryCondition.setEndTmEnd(DateUtils.formatStringToDate(endTmEnd + " 23:59:59", DateUtils.YYYY_MM_DDHHMMSS));
		}
	}
	
	/**
	 * 获取查询条件
	 * 1、待办列表的查询条件
	 * 2、挂起列表的查询条件
	 * 3、完结列表的查询条件
	 * @param request
	 * @param flowQueryCondition
	 */
	private void getFlowQueryRequestParms(HttpServletRequest request, FlowQueryCondition flowQueryCondition) {
		String flowDefNm = request.getParameter("flowDefNm");
		String taskNm = request.getParameter("taskNm");
		String cstNm = request.getParameter("cstNm");//大字段值
		String prjNm = request.getParameter("prjNm");//大字段值
		String orgDispNm = request.getParameter("orgDispNm");//大字段值
		String businessType = request.getParameter("businessType");
		String bizResCd = request.getParameter("bizResCd");//任务源
		String initiator = request.getParameter("initiator");
		String viKey = request.getParameter("viKey");//大字段值(主要关键字)
		String startTmStart = request.getParameter("startTmStart");
		String startTmEnd = request.getParameter("startTmEnd");
		String endTmStart = request.getParameter("endTmStart");
		String endTmEnd = request.getParameter("endTmEnd");
		String procNo = request.getParameter("procNo");//流程编号
		String searchOrgCd = request.getParameter("searchOrgCd");//组织机构代码-查询使用-和正常使用的当前组织机构代码区分
		String assigneeNm = request.getParameter("assigneeNm");//新处理人
		String ownerNm = request.getParameter("ownerNm");//原处理人
		String initiatorNo = request.getParameter("initiatorNo");//发起人工号
		String assigneeNo = request.getParameter("assigneeNo");//新处理人工号
		String ownerNo = request.getParameter("ownerNo");//原处理人工号

		if(StringUtils.isNotEmpty(procNo)){
			flowQueryCondition.setProcNo(procNo);
		}
		
		if(StringUtils.isNotEmpty(flowDefNm)){
			flowQueryCondition.setFlowDefNm(flowDefNm);
		}
		
		if(StringUtils.isNotEmpty(taskNm)){
			flowQueryCondition.setTaskNm(taskNm);
		}
		
		if(StringUtils.isNotEmpty(orgDispNm)){
			flowQueryCondition.setOrgDispNm(orgDispNm);
		}
		
		if(StringUtils.isNotEmpty(searchOrgCd)){
			flowQueryCondition.setSearchOrgCd(searchOrgCd);
		}
		/*if(StringUtils.isNotEmpty(businessType)){
			flowQueryCondition.setBusinessType(businessType);
		}*/
		if(StringUtils.isNotEmpty(bizResCd)){
			flowQueryCondition.setBizResCd(bizResCd);
		}
		if(StringUtils.isNotEmpty(initiator)){
			flowQueryCondition.setInitiatorNm(initiator);
		}
		
		if(StringUtils.isNotEmpty(assigneeNm)){
			flowQueryCondition.setAssigneeNm(assigneeNm);
		}
		
		if(StringUtils.isNotEmpty(ownerNm)){
			flowQueryCondition.setOwnerNm(ownerNm);
		}
		
		StringBuffer key = new StringBuffer();//大字段查询
		
		if(StringUtils.isNotEmpty(viKey)){
			key.append(FlowConstant.FLOW_QUERY_CONDITION_SEPERATOR);
			key.append(viKey);
		}
		
		if(StringUtils.isNotEmpty(businessType)){
			key.append(FlowConstant.FLOW_QUERY_CONDITION_SEPERATOR);
			key.append(businessType);
		}
		
		if(StringUtils.isNotEmpty(cstNm)){
			flowQueryCondition.setCstNm(cstNm);
		}
			
		if(StringUtils.isNotEmpty(prjNm)){
			key.append(FlowConstant.FLOW_QUERY_CONDITION_SEPERATOR);
			key.append(prjNm);
		}
			
		if(StringUtils.isNotEmpty(orgDispNm)){
			key.append(FlowConstant.FLOW_QUERY_CONDITION_SEPERATOR);
			key.append(orgDispNm);
		}
		
		if(StringUtils.isNotEmpty(key.toString())){
			flowQueryCondition.setViKey(key.toString());
		}
		
		if(StringUtils.isNotEmpty(startTmStart)){
			flowQueryCondition.setStartTmStart(DateUtils.formatStringToDate(startTmStart + " 00:00:00", DateUtils.YYYY_MM_DDHHMMSS));
		}
		if(StringUtils.isNotEmpty(startTmEnd)){
			flowQueryCondition.setStartTmEnd(DateUtils.formatStringToDate(startTmEnd + " 23:59:59", DateUtils.YYYY_MM_DDHHMMSS));
		}
		if(StringUtils.isNotEmpty(endTmStart)){
			flowQueryCondition.setEndTmStart(DateUtils.formatStringToDate(endTmStart + " 00:00:00", DateUtils.YYYY_MM_DDHHMMSS));
		}
		if(StringUtils.isNotEmpty(endTmEnd)){
			flowQueryCondition.setEndTmEnd(DateUtils.formatStringToDate(endTmEnd + " 23:59:59", DateUtils.YYYY_MM_DDHHMMSS));
		}

		if(StringUtils.isNotEmpty(initiatorNo)){
			flowQueryCondition.setInitiatorNo(initiatorNo);
		}

		if(StringUtils.isNotEmpty(assigneeNo)){
			flowQueryCondition.setAssigneeNo(assigneeNo);
		}

		if(StringUtils.isNotEmpty(ownerNo)){
			flowQueryCondition.setOwnerNo(ownerNo);
		}
	}
	
	
	/**
	 * 到可发起流程列表页面
	 */
	@RequestMapping(value = "/toForStartListPage.do", method = { RequestMethod.GET})
	public ModelAndView toForStartListPage(HttpServletRequest request, HttpServletResponse response) {
		String modelTyp=request.getParameter("modelTyp");//模块类型
		BaseLogUtils.info(logger, "toForStartListPage", "加载发起流程列表页面.",CurrentThreadContext.getCurrentUserName());
		ModelAndView view = new ModelAndView("flow/flow/flowForStartList");
		view.addObject("modelTyp", modelTyp);
		return view;
	}
	
	/**
	 * 初始化可发起流程列表
	 */
	@RequestMapping(value = "/initForStartList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initForStartList(HttpServletRequest request, HttpServletResponse response) {
		SysFlowManageVQueryCondition qc = new SysFlowManageVQueryCondition();
        String modelTyp=request.getParameter("modelTyp");//模块类型
		if (StringUtils.isNotEmpty(modelTyp)) {
			qc.setModelTyp(modelTyp);
		}
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		
        List<SysFlowManageVVO> list = this.flowService.searchFlowManageVListForStart(qc);
        if(CollectionUtils.isNotEmpty(list)){
            return new ListPageVO<SysFlowManageVVO>(list, list.size());
        }else{
            return null;
        }
	}
	
	
	/**
	 * 重新设置任务处理人
	 */
	@RequestMapping(value = "/modifyAssignTask.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object modifyAssignTask(HttpServletRequest request, HttpServletResponse response) {
		//日志-开始时间
		Long startTim = System.currentTimeMillis();
		BaseLogUtils.info(logger, "modifyAssignTask", "重新设置任务处理人.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());

		String usr = request.getParameter("usr");//用户集合
		String taskIds = request.getParameter("taskIds");//任务ID

		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");

		if(StringUtils.isEmpty(taskIds)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("任务ID不能为空！");
			return result;
		}

		if(StringUtils.isEmpty(usr)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("处理人员不能为空！");
			return result;
		}

		try {
			JSONObject user = JSONObject.parseObject(usr);
			Set<String> set = user.keySet();
			String usrId=null;
			String usrNm=null;
			for(String key : set) {
				usrId = key;
				usrNm = user.getString(usrId);
			}

			List<String> taskIdList = new ArrayList<>();
			JSONArray taskIdArray = JSONArray.fromObject(taskIds);
			for (Object object : taskIdArray) {
				taskIdList.add(object.toString());
			}

			Boolean pass =this.flowService.batchModifyAssignTask(taskIdList, usrId, usrNm);
			if(!pass){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("操作失败！");
			}
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			BaseLogUtils.info(logger, "modifyAssignTask", "业务异常:" + e.getMessage());
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误！");
			BaseLogUtils.error(logger, "modifyAssignTask", "系统错误", e);
		}
		//日志--结束时间
		Long endTim = System.currentTimeMillis();
		BaseLogUtils.info(logger, "modifyAssignTask", "重新设置任务处理人.耗时：" + (endTim-startTim), CurrentThreadContext.getCurrentUserName());

		return result;
	}

	/**
	 * 获取下一节点操作人信息
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/getFlowNextAssigne.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object getFlowNextAssigne(HttpServletRequest request, HttpServletResponse response) {
		String key = request.getParameter("key");//用户集合

		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");

		if(StringUtils.isEmpty(key)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("KEY不能为空！");
			return result;
		}
		try {
			String assignee=this.flowService.getNextFlowAssignee(key);
			result.setSuccess(BaseConstant.IS_YESNO_YES);
			if(StringUtils.isNotBlank(assignee)) {
				result.setInfo("下一节点操作人:"+assignee);
			}else {
				result.setInfo("流程处理成功");
			}
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			BaseLogUtils.info(logger, "getFlowNextAssigne", "业务异常:" + e.getMessage());
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误！");
			BaseLogUtils.error(logger, "getFlowNextAssigne", "系统错误", e);
		}
		return result;
	}


	//恢复
	/**
	 * 到我的任务管理列表页面
	 */
	@RequestMapping(value = "/toTaskDBManagePage.do", method = { RequestMethod.GET})
	public ModelAndView toTaskDBManagePage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("flow/sysflowmanage/taskDBManage");
		//任务源
		List<KeyValueVO> businessSourceList = this.flowService.searchBusinessSourceList();
		view.addObject("businessSourceList", businessSourceList);
		//业务类型
		List<KeyValueVO> businessTypeList = this.flowService.searchBusinessTypeList();
		view.addObject("businessTypeList", businessTypeList);
		return view;
	}

	/**
	 * 作废流程
	 */
	@RequestMapping(value = "/modifyFlowCancel.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object modifyFlowCancel(HttpServletRequest request, HttpServletResponse response) {
		String taskId = request.getParameter("taskId");
		String processInstanceId = request.getParameter("processInstanceId");
		String businessType = request.getParameter("businessType");
		String businessKey = request.getParameter("businessKey");
		String pDefKey = request.getParameter("processDefinitionKey");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		if(StringUtils.isEmpty(taskId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("任务ID不能为空！");
			return result;
		}
		if(StringUtils.isEmpty(processInstanceId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("流程实例ID不能为空！");
			return result;
		}
		try {
			Boolean pass = this.flowService.modifyFlowCancel(CurrentThreadContext.getCurrentUserId(), taskId, processInstanceId);
			if(null == pass || pass == false){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("操作失败！");
			}
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			BaseLogUtils.info(logger, "modifyFlowCancel", "业务异常:" + e.getMessage());
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误！");
			BaseLogUtils.error(logger, "modifyFlowCancel", "系统错误", e);
		}
		return result;
	}

	/**
	 * 变更发起人
	 */
	@RequestMapping(value = "/modifyInitiator.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object modifyInitiator(HttpServletRequest request, HttpServletResponse response) {
		//日志-开始时间
		Long startTim = System.currentTimeMillis();
		BaseLogUtils.info(logger, "modifyInitiator", "变更发起人.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());

		String usr = request.getParameter("usr");//用户
		String processInstanceIds = request.getParameter("processInstanceIds");

		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");

		if(StringUtils.isEmpty(processInstanceIds)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("流程实例ID不能为空！");
			return result;
		}

		if(StringUtils.isEmpty(usr)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("发起人员不能为空！");
			return result;
		}

		try {
			String usrId = "";
			String usrNm = "";
			JSONObject user = JSONObject.parseObject(usr);
			Set<String> set = user.keySet();
			for(String key : set){
				usrId = key;
				usrNm = user.getString(usrId);
			}

			List<String> processInstanceList = new ArrayList<>();
			JSONArray taskIdArray = JSONArray.fromObject(processInstanceIds);
			for (Object object : taskIdArray) {
				processInstanceList.add(object.toString());
			}

			Boolean pass = this.flowService.batchModifyInitiator(processInstanceList, usrId, usrNm);
			if(!pass){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("操作失败！");
			}
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			BaseLogUtils.info(logger, "modifyInitiator", "业务异常:" + e.getMessage());
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误！");
			BaseLogUtils.error(logger, "modifyInitiator", "系统错误", e);
		}
		//日志--结束时间
		Long endTim = System.currentTimeMillis();
		BaseLogUtils.info(logger, "modifyInitiator", "变更发起人.耗时：" + (endTim-startTim), CurrentThreadContext.getCurrentUserName());
		return result;
	}

	/**
	 * 选择组织中的人员WIN窗口内容
	 */
	@RequestMapping(value = "/toCheckboxUsrWinPage.do", method = { RequestMethod.GET})
	public ModelAndView toCheckboxUsrWinPage(HttpServletRequest request, HttpServletResponse response) {
		String isMore = request.getParameter("isMore");
		ModelAndView view = new ModelAndView("flow/flow/flowCheckboxUsr");
		view.addObject("isMore", isMore);
		return view;
	}


	/**
	 * 到流程设置页面
	 */
	@RequestMapping(value = "/toFlowSettingPage.do", method = { RequestMethod.GET})
	public ModelAndView toFlowSettingPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("flow/sysflowmanage/flowSettingList");
		return view;
	}

	/**
	 * 到流程设置新增页面
	 */
	@RequestMapping(value = "/toFlowSettingAddPage.do", method = { RequestMethod.GET})
	public ModelAndView toFlowSettingAddPage(HttpServletRequest request, HttpServletResponse response) {
		String orgCd = request.getParameter("orgCd");
		ModelAndView view = new ModelAndView("flow/sysflowmanage/flowSettingAdd");
		//获取模块类型数据字典项
		List<KeyValueVO> modelTypList = this.flowService.searchModelTypList();
		if(CollectionUtils.isNotEmpty(modelTypList)){
			view.addObject("modelTypList", com.alibaba.fastjson.JSONArray.toJSON(modelTypList));
		}else{
			view.addObject("modelTypList", new JSONArray());
		}
		view.addObject("orgCd", orgCd);
		return view;
	}

	/**
	 * 同步流程引擎中流程定义数据
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/syncFlowDefDataFromRemote.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object syncFlowDefDataFromRemote(HttpServletRequest request, HttpServletResponse response) {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_SYNC_SUCC);
		try {
			Boolean pass = this.flowService.syncFlowDefDataFromRemote(CurrentThreadContext.getCurrentSysCd());
			if(null == pass || pass == false){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_SYNC_FAIL);
			}
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			logger.info(e.getMessage());
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			logger.info(SysLogConstant.LOG_CMM_SYS_ERROR+e.getMessage());
		}
		return result;
	}

	@RequestMapping(value = "/toChooseUsrWinPageDialog.do", method = { RequestMethod.GET})
	public ModelAndView toChooseUsrWinPageDialog(HttpServletRequest request, HttpServletResponse response) {
		extSlf4jLogger.info("选择组织用户页面，request：{}", JSON.toJSONString(request.getParameterMap()));
		String isMore = request.getParameter("isMore");
		String mgrType = request.getParameter("mgrType");
		String dataId = request.getParameter("dataId");
		String dataTypCd = request.getParameter("dataTypCd");
		ModelAndView view = new ModelAndView("flow/flow/flowCheckboxUsrDialog");
		view.addObject("isMore", isMore);
		view.addObject("mgrType", mgrType);
		view.addObject("dataId", dataId);
		view.addObject("dataTypCd", dataTypCd);
		return view;
	}



}
